/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uploadphotobucket;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import javax.swing.SwingWorker;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.json.JSONException;
import org.json.JSONObject;
import uploadphotobucket.action.ActionPhotobucket;
import utils.Album;
import utils.AnalyzeAlbum;
import utils.Browser;
import utils.Media;
import utils.Message;
import utils.ReadWriteFile;

/**
 *
 * @author banhbaochay
 */
public class TestCore {

    SwingWorker<String, Void> worker = new SwingWorker<String, Void>() {

        @Override
        protected String doInBackground() throws Exception {
            return "Hello World";
        }
    };


    public static void main(String[] args) throws Exception {
        Browser b = new Browser();
        System.out.println(b.isDesktopSupported());
        System.out.println(b.isBrowseSupported());
        
    }

    // <editor-fold defaultstate="collapsed" desc="accessAccount photobucket">
    public void accessAcount() throws Exception {
        String oauthConsumerKey = ResourceBundle.getBundle("consumer").getString("oauth.consumer");
        String oauthConsumerSecret = ResourceBundle.getBundle("consumer").getString("oauth.consumer.key");
        ActionPhotobucket action = new ActionPhotobucket(oauthConsumerKey, oauthConsumerSecret);
        Map<String, String> consumerMap = new HashMap<String, String>();
//        action.request();
//        consumerMap = Common.getTokenRespone(action.request("xml"));

        /*
         * Login
         */
        HttpClient httpclient = new DefaultHttpClient();
        try {

            HttpGet httpget = new HttpGet("http://photobucket.com/apilogin/login?oauth_token=" + consumerMap.get("oauth_token"));
            System.out.println(httpget.getURI());
            ResponseHandler<String> response = new BasicResponseHandler();
            String responseBody = httpclient.execute(httpget, response);
//            System.out.println(responseBody);
            httpget.abort();
        } finally {
            httpclient.getConnectionManager().shutdown();
        }

        try {
            httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://photobucket.com/apilogin/login");
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("usernameemail", "gocobin"));
            params.add(new BasicNameValuePair("password", "111111"));
            UrlEncodedFormEntity entityForm = new UrlEncodedFormEntity(params, HTTP.UTF_8);
            httppost.setEntity(entityForm);
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            System.out.println("Status line: " + response.getStatusLine());
            if (entity != null) {
                InputStream instream = entity.getContent();
                try {
                    BufferedReader in = new BufferedReader(new InputStreamReader(instream));
                    String line = null;
                    while ((line = in.readLine()) != null) {
                        System.out.println(line);
                    }
                } finally {
                    instream.close();
                }
            }// end if entity != null
        } finally {
            httpclient.getConnectionManager().shutdown();
        }

    }// end accessAcount method
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="ping photobucket">
    public void ping() throws Exception {
        String oauthConsumerKey = ResourceBundle.getBundle("consumer").getString("oauth.consumer");
        String oauthConsumerSecret = ResourceBundle.getBundle("consumer").getString("oauth.consumer.key");
        ActionPhotobucket action = new ActionPhotobucket(oauthConsumerKey, oauthConsumerSecret);
        JSONObject result = action.ping();
        System.out.println(result);
//        System.out.println(action.getResponseString());
    }// end ping method
    // </editor-fold>

    public void request() throws Exception {
        String oauthConsumerKey = ResourceBundle.getBundle("consumer").getString("oauth.consumer");
        String oauthConsumerSecret = ResourceBundle.getBundle("consumer").getString("oauth.consumer.key");
        ActionPhotobucket action = new ActionPhotobucket(oauthConsumerKey, oauthConsumerSecret);
        JSONObject o = action.request();
        System.out.println(o);
    }// end request method

    public void testJSon() throws JSONException {
        JSONObject object = new JSONObject("{\"status\":\"OK\",\"content\":{\"pong\":\"(read)\",\"request\":{\"jsonp_callback\":"
                + "\"eatResponse\",\"oauth_consumer_key\":\"00000000\",\"oauth_nonce\":\"3b190e959c7e6de518cb1cc31f2c6abc\","
                + "\"oauth_signature\":\"f5Arsh02H9KKT4Lg1BOBROgmjO0=\",\"oauth_signature_method\":\"HMAC-SHA1\","
                + "\"oauth_timestamp\":\"1215623625\",\"oauth_version\":\"1.0\"}},\"format\":\"jsonp\",\"method\":\"GET\","
                + "\"timestamp\":1215623625}");
//        System.out.println(object.getJSONArray(""));
    }// end testJSon method
}


class A {
    List<B> list;

    public A() {
        list = new ArrayList<B>();
        
    }
    void add(B b) {
        list.add(b);
    }
    
}

class B {

    int x = 2;
    void increase() {
        x++;
    }
    void modify() {
        s = "a";
    }
    String s = "as";
}